﻿using System;
using System.IO;
using System.Text;
using YEA.Infrastructure.Gateway;
using YEA.Infrastructure.Gateway.Converter;

namespace SimpleAsyncReceiver
{
    class Program
    {
        static void Main(string[] args)
        {
            var mp = new MessageProcessor();
            using (var cf = new GatewayFactory())
            {
                cf.GetAsyncReceiver("orderReceiver",mp.ConsumeMessage);
            }
        }
    }
    class MessageProcessor : IMessageConsumer
    {

        public void ConsumeMessage(Message message, RabbitMQ.Client.IModel channel, DeliveryHeader header)
        {
            try
            {
                var str = MessageToStringConverter.Convert(message);
                channel.BasicAck(header.DeliveryTag, false);
            }
            catch (Exception ex)
            {
                channel.BasicReject(header.DeliveryTag, true);
            }
        }
        
    }
}
